
#include <lua.hpp>
#include <stdint.h>
#include "entity_factory.hpp"

int process_lua_file(lua_State *L, const char* file)
{
  printf("Running lua file %s...\n", file);
  int status = luaL_dofile(L, file);

  if(status) { //Error condition
    //Print the error messsage sitting on the top of the stack
    fprintf(stderr, "%s\n", lua_tostring(L, -1));
    lua_pop(L,1); //Pop the error message from the stack
  }
  return status;
}


int main()
{
  lua_State *L = lua_open();

  luaL_openlibs(L); //Load lua libraries

  int end = 0;
  end = process_lua_file(L, "base.lua");
  if(!end)
    end = process_lua_file(L, "entity.lua");
  engine::register_functions(L);

  //Create a few entities
  engine::shared_entity_factory::Create(L, "Base_Entity");
  engine::shared_entity_factory::Create(L, "Base_Entity");

  lua_close(L);
  return 0;
}
